home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
turbovis
/
tvtool17.zip
/
STRINGS.H
< prev
next >
Wrap
C/C++ Source or Header
|
1993-09-20
|
19KB
|
731 lines
/*
* Copyright (C) 1993 Marc Stern (internet: stern@mble.philips.be)
*
* File : strings.h
*
* Description : strings management
*
*/
#ifndef __Strings_H
#define __Strings_H
/* INCLUDE FILES */
#include "c2cpp.h"
#include <string.h>
#include <stddef.h>
/***
* Function : foreach
*
* Description : Loop on each token of a string
*
* Parameters : out char *word pointer that will contain word (token)
* in/out char *string string to tokenize
*
* Side-effects: Macro, so be careful.
* '\0' will be inserted into string.
*
* Return code : none
***/
#define foreach( word , string ) \
for ( word = strtok(string," ") ; word ; word = strtok(NULL," ") )
/***
* Function : STRMIN/STRMAX
*
* Description : return min/max of two strings
*
* Parameters : in char *str1
* in char *str2
*
* Side-effects: Macro, so be careful.
*
* Return : pointer to min/max of the two strings
***/
#define STRMIN( str1 , str2 ) ( (strcmp(str1 , str2) < 0) ? str1 : str2 )
#define STRMAX( str1 , str2 ) ( (strcmp(str1 , str2) > 0) ? str1 : str2 )
/***
* Function : strisequal
*
* Description : Test equality of two strings
*
* Parameters : in char *str1
* in char *str2
*
* Return : 0 or 1
***/
#define strisequal( string1 , string2 ) ( ! strcmp(string1 , string2) )
/*** For switch/case-like string manipulation
usage: STRWITCH( string )
{
STRCASE "string1": ... ;
STRCASE "string2": ... ; break ;
...
STRDEFAULT : ... ;
} STRENDSWITCH
***/
#define STRSWITCH( _str ) { char *_tmp_s = _str ; \
int _tmp_flag = 0 ; \
do { if ( _tmp_flag )
#define STRCASE( _str ) ( _tmp_flag = 1 ) ; } \
if ( _tmp_flag || ! strcmp(_tmp_s, _str) ) { 0 ? 0
#define STRDEFAULT 0 ; } { 0 ? 0
#define STRENDSWITCH } while (0) ; }
/* TYPES DEFINITIONS */
typedef enum { align_left , align_right , align_center } align_type ;
typedef enum { LOWER = 5 , UPPER } casetype ;
/* FUNCTIONS DEFINITIONS */
/***
* Function : strleft
*
* Description : Copy the first ... characters of a string.
* Like strncpy but add a '\0' at the end of the output string.
*
* Decisions : If given length > string length : normal strcpy
* If given length <= 0 returns an empty string.
*
* Parameters : out char *out_str result
* in char *in_str in string
* in int length length to be copied
*
* Return code : pointer to result.
*
* OS/Compiler : All
*/
EXTERN char *strleft( char* , const char* , int ) ;
/***
* Function : strright
*
* Description : Copy the last ... characters of a string.
*
* Decisions : If given length > string length : normal strcpy
* If given length <= 0 returns an empty string.
*
* Parameters : out char *out_str result
* in char *in_str in string
* in int length length to be copied
*
* Return code : pointer to result.
*
* OS/Compiler : All
*/
EXTERN char *strright( char* , const char* , int ) ;
/***
* Function : strmid
*
* Description : Copy n characters of a string, begining at a given position
* ( form 1 to ... )
*
* Decisions : Stops at the end of input string if given length
* is too big or length = 0.
* If given length or position < 0 returns an empty string.
*
* Parameters : out char *out_str result
* in char *in_str in string
* in int pos position where begin to copy
* in int length length to be copied
*
* Return code : pointer to result.
*
* OS/Compiler : All
*/
EXTERN char *strmid( char* , const char* , int , int ) ;
/***
* Function : stralign
*
* Description : Copy an input string in an output string
* with specified alignement (blank padding).
*
* Decisions : If given length < 0 returns an empty string.
*
* Parameters : out char *out_str result
* in char *in_str in string
* in align_type casetype type
* in int length length to be copied
*
* Value : type = { align_left, align_center, align_right }
*
* Return code : pointer to result.
*
* OS/Compiler : All
*/
EXTERN char *stralign( char* , const char* , align_type , int ) ;
/***
* Function : strmvstr
*
* Description : Copy an input string in an output string
* with replacing all occurences of a target string.
*
* Parameters : out char *out_str result
* in char *in_str in string
* in char *target target string to replace
* in char *new_str string to put in place of target
*
* Return code : pointer to result.
*
* OS/Compiler : All
***/
EXTERN char *strmvstr( char* , const char* , const char* , const char* ) ;
/***
* Function : strmvchr
*
* Description : Replace all occurences of a target character
* by a new character.
*
* Parameters : in/out char *string
* in char target target char to replace
* in char new_char char to put in place of target
*
* Return code : pointer to result.
*
* OS/Compiler : All
***/
EXTERN char *strmvchr( char* , char , char ) ;
/***
* Function : strrmstr
*
* Description : Removing all occurences of a target string.
*
* Parameters : in/out char *string
* in char *target target string to remove
*
* Decisions : Same implementation as strmvstr without copying
* a replacement string.
* Could also be implemented as
* strmvstr( ptr, ptr, target, "" )
* but should be less efficient.
*
* Return code : pointer to result.
*
* OS/Compiler : All
***/
EXTERN char *strrmstr( char* , const char* ) ;
/***
* Function : strrmchr
*
* Description : Removing all occurences of a target character.
*
* Parameters : in/out char *string
* in char target target char to remove
*
* Return code : pointer to result.
*
* OS/Compiler : All
***/
EXTERN char *strrmchr( char* , char ) ;
/***
* Function : strinsert
*
* Description : Insert a string in another.
*
* Parameters : out char *out_str out string
* in char *in_str in string
* in char *to_insert in string to insert into the other
* in int place place to insert string
*
* Decisions : Does nothing if place specified out of range.
*
* Return : pointer to result
*
* OS/Compiler : All
***/
EXTERN char *strinsert( char* , const char* , const char* , int ) ;
/***
* Function : strend
*
* Description : Returns a pointer to the '\0' ending a string
*
* Parameters : in char *in_str in string
*
* Return code : pointer to the '\0' ending the string..
*
* OS/Compiler : All
***/
EXTERN char *strend( const char* ) ;
/***
* Function : strskip
*
* Description : Skip 'n' words from a string.
*
* Decisions :
*
* Parameters : in